package com.xiaoyu.izf.controller;

import com.xiaoyu.izf.annotation.RequestAuth;
import com.xiaoyu.izf.model.Vocation;
import com.xiaoyu.izf.service.VocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 行业
 */
@RestController
@RequestMapping("/vocation")
public class VocationController {

    @Autowired
    private VocationService vocationService;

    /**
     * 行业列表，要查商户类别regionId=1
     * @param vocationId
     * @return
     */
    @RequestMapping("/list")
    @RequestAuth
    public List<Vocation> list(int vocationId){
        return vocationService.findByParentId(vocationId);
    }

    @RequestMapping("/list_all")
//    @RequestAuth
    public List<Vocation> listALl(){

        List<Vocation> list = vocationService.findByParentId(0);
        for (Vocation vocation:list){
            List<Vocation> list1 = vocationService.findByParentId(vocation.getVocationId());
            vocation.setChildren(list1);
            for (Vocation vocation1:list1){
                List<Vocation> list2 = vocationService.findByParentId(vocation1.getVocationId());
                vocation1.setChildren(list2);
            }
        }

        return list;
    }
}
